package com.vvlive.caibao.smartcity.utils;

import android.graphics.Color;
import android.text.TextUtils;

/**
 * Created by zhj on 2015/6/29.
 */
public class RandomUtil {

    private final static int DEFAULT_MOBILE_LENGTH = 11;
    private final static int DEFAULT_PHONE_LENGTH = 7;

    static int[] colors = {Color.RED, Color.BLACK, Color.DKGRAY};

    /**
     * 生成随机数
     * @param max
     * @return
     */
    public static int getRandomNumber(int max){
//        return (int) Math.round(Math.random() * (max - 1));
        return (int)( Math.round(Math.random() * (max - 1)) + 1 );
    }

    public static String getRandomMobile(){

        int color = colors[getRandomNumber(colors.length)];

        return getRandomMobile(DEFAULT_MOBILE_LENGTH);
    }

    public static String getRandomMobile(int length){
        return getRandomNumberString(length, "1");
    }

    public static String getRandomPhone(){
        return getRandomPhone(DEFAULT_PHONE_LENGTH);
    }

    public static String getRandomPhone(int length){
        return getRandomNumberString(length, null);
    }

    private static String getRandomNumberString(int length, String first){
        StringBuilder builder = new StringBuilder(TextUtils.isEmpty(first) ? "" : first);
        length = !TextUtils.isEmpty(first) ? length - 1 : length;
        for(int i = 0; i < length; i++){
            builder.append(getRandomNumber(9));
        }
        return builder.toString();
    }
}
